<?php
namespace app\admin\controller;
use think\Db;
class userpay extends Common
{

    //用户管理
    public function index()
    {   
        if(request() -> isPost()){
            $key = input('post.key');
            $page = input('page')?input('page'):1;
            $pageSize =input('limit')?input('limit'):10;
            $list = DB::table('pre_common_member')
                  ->alias('a')
                  ->join('pre_common_member_count b','a.uid = b.uid')
                  ->field('b.extcredits2,a.*')
                  ->where('a.uid|a.username','like','%'.$key.'%')
                  ->order('uid desc')
                  ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
                  ->toArray();
            if($list['data']){     
                foreach ($list['data'] as $key => $value) {
                    $list['data'][$key]['groupexpiry'] = date('Y-m-d H:i:s',$value['groupexpiry']);
                    $list['data'][$key]['regdate'] = date('Y-m-d H:i:s',$value['regdate']);
                }  
            }             
            return json(['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1]);
        }
        return $this->fetch();
    }

    //编辑公告
    public function edit($uid='')
    {
        if(request() -> isPost()){
            $id = input('post.uid');
            $groupexpiry = strtotime(trim(input('post.groupexpiry')));
            $update =db('common_member')->where('uid', $id)->update(['groupexpiry' => $groupexpiry]);
            if($update){
                return json(['code'=>1,'msg'=>'编辑成功','url' => url('userpay/index')]);
            }else{
                return json(['code'=>0,'msg'=>'编辑失败']);
            }
        }else{
            $list = db('common_member')->where('uid',$uid)->find();
            $this->assign('list',$list);
            return $this->fetch();
        }
    }

}